use super::item::LogItem;


/// 只保留很小的一部分日志
#[derive(Debug, Default)]
pub struct VecLogShort {
    pub count: u32,
    pub items: Vec<LogItem>,
}

impl VecLogShort {
    pub fn new() -> Self {
        Self {
            count: 0,
            items: Vec::new(),
        }
    }
    pub fn trim_start(&mut self, remain: usize) {
        if self.items.len() > 2 * remain {
            self.items.drain(0..self.items.len() - remain);
        }
    }
}

impl VecLogShort {
    pub fn error(&mut self, message: String) {
        let item = LogItem::error(self.count, message);
        self.count += 1;
        self.items.push(item);
    }
    pub fn warn(&mut self, message: String) {
        let item = LogItem::warn(self.count, message);
        self.count += 1;
        self.items.push(item);
    }
    pub fn info(&mut self, message: String) {
        let item = LogItem::info(self.count, message);
        self.count += 1;
        self.items.push(item);
    }
    pub fn debug(&mut self, message: String) {
        let item = LogItem::debug(self.count, message);
        self.count += 1;
        self.items.push(item);
    }
    pub fn trace(&mut self, message: String) {
        let item = LogItem::trace(self.count, message);
        self.count += 1;
        self.items.push(item);
    }
}

